﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web.Mvc
{
    /// <summary>
    /// 对htmlhelper进行扩展
    /// </summary>
    public static class HtmlHelperExt
    {
        /// <summary>
        /// 字符串截取
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="str">要处理的字符串</param>
        /// <param name="length">长度</param>
        /// <param name="symbol">占位符</param>
        /// <returns></returns>
        public static MvcHtmlString GetSubString(this HtmlHelper helper, string str, int length, string symbol)
        {
            string result = "";
            if (!string.IsNullOrEmpty(str))
            {
                str = str.Trim();
                if (str.Length > length)
                {
                    str = str.Substring(0, length) + symbol;
                }
                result = str;
            }
            MvcHtmlString htmlString = MvcHtmlString.Create(result);
            return htmlString;
        }
    }
}
